package com.infore.siteManagement.repository;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.infore.siteManagement.outEntity.SysUserStation;

public interface ISysUserStationRepository extends JpaRepository<SysUserStation, String> {

    List<SysUserStation> findByUserId(String userId);
    
	@Modifying
	@Transactional
	@Query(value="delete from SYS_USER_STATION where user_id =:userId",nativeQuery=true)
	int delByUserId(@Param("userId")String userId);
	
	@Modifying
	@Transactional
	@Query(value="delete from SYS_USER_STATION where user_id =:userId and station_id=:stationId",nativeQuery=true)
	int delByUserIdAndStation(@Param("userId")String userId,@Param("stationId")String stationId);
	
	@Modifying
	@Transactional
	@Query(value="delete from SYS_USER_STATION where station_id in (:ids)",nativeQuery=true)
	int delByStationId(@Param("ids")List<String> ids);
	
	@Query(value="select t.station_name,t.station_id,t.station_mn,s.user_id from SYS_USER_STATION s left join STATION t on t.station_id = s.station_id "
			+ "where t.station_id is not null and s.user_id in (:userIdList)",nativeQuery=true)
	List<Map<String, Object>>querystationForSpareByUserId(@Param("userIdList") List<String>userIdList);

}
